package com.atguigu.juc.study.chapter09.atomics;

import lombok.Data;

import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.LongAccumulator;
import java.util.concurrent.atomic.LongAdder;

/**
 * @author : leimingchao
 * @date Date : 2022年06月16日 0:27
 */
@Data
public class ClickNumber {

    private int number = 0;

    public synchronized void clickBySynchronized() {

        number++;
    }

    AtomicLong atomicLong = new AtomicLong(0);

    public void clickByAtomicLong() {
        atomicLong.getAndIncrement();
    }

    LongAdder longAdder = new LongAdder();

    public void clickByLongAdder() {

        longAdder.increment();
    }

    LongAccumulator longAccumulator = new LongAccumulator((x, y) -> x+ y, 0);
    public void clickByLongAccumulator() {
        longAccumulator.accumulate(1);
    }
}
